﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace _13.HappyNumbersInSequence
{
    class HappyNumbersInSequence
    {
        static StringBuilder output = new StringBuilder();
        static ListComparer listComparer = new ListComparer();
        static TreeMultiSet<List<int>> longestLists = new TreeMultiSet<List<int>>(listComparer);
        static List<int> sequence = new List<int>();

        static void Main(string[] args)
        {
            //TestGenerator.CreateTest("test12.in.txt");
            //ReadInput(@"..\..\Tests\test12.in.txt");
            //PrintOutput(@"..\..\Tests\test12.out.txt");
            ReadInput();
            PrintOutput();
        }

        private static void ReadInput()
        {
            int sum = int.Parse(Console.ReadLine());
            PrepareInputSequence(Console.ReadLine());
            FindLongestSequence(sum);
        }

        private static void ReadInput(string fileName)
        {
            StreamReader reader = new StreamReader(fileName);
            int sum;
            using (reader)
            {
                sum = int.Parse(reader.ReadLine());
                PrepareInputSequence(reader.ReadLine());
            }
            FindLongestSequence(sum);
        }

        private static void PrepareInputSequence(string inputLine)
        {
            string[] stringSequence = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string item in stringSequence)
            {
                sequence.Add(int.Parse(item));
            }
        }

        private static void FindLongestSequence(int sum)
        {
            int currentSum = 0;
            for (int startIndex = 0; startIndex < sequence.Count; startIndex++)
            {
                List<int> newList = new List<int>();
                currentSum = 0;
                for (int i = startIndex; i < sequence.Count; i++)
                {
                    newList.Add(sequence[i]);
                    currentSum += sequence[i];
                    if (currentSum == sum)
                    {
                        longestLists.Add(new List<int>(newList));
                        if (longestLists.Count > 10)
                        {
                            longestLists.DeleteLast();
                        }
                    }
                }
            }
        }

        private static void PrintOutput()
        {
            PrepareOutPut();
            Console.WriteLine(output);
        }

        private static void PrintOutput(string fileName)
        {
            PrepareOutPut();
            StreamWriter writer = new StreamWriter(fileName);
            using (writer)
            {
                writer.Write(output);
            }
        }

        private static void PrepareOutPut()
        {
            if (longestLists.Count == 0)
            {
                output.Append(-1);
            }
            foreach (List<int> list in longestLists)
            {
                output.Append("[");
                foreach (int item in list)
                {
                    output.Append(item + ",");
                }
                output.Remove(output.Length - 1, 1);
                output.Append("]");
                output.Append(System.Environment.NewLine);
            }
        }

    }
    class ListComparer : IComparer<List<int>>
    {
        public int Compare(List<int> x, List<int> y)
        {
            if (x.Count == y.Count)
            {
                for (int i = 0; i < x.Count; i++)
                {
                    if (x[i] != y[i])
                    {
                        return x[i].CompareTo(y[i]);
                    }
                }
                return 0;
            }
            else
            {
                return -1 * x.Count.CompareTo(y.Count);
            }
        }
    }
}
